﻿using System;
using System.Data;
using System.Collections.Generic;
namespace EnterpriseFund.BLL
{
    /// <summary>
    /// 业务逻辑类PrvFunctList 的摘要说明。
    /// </summary>
    public class PrvFunctList
    {
        private readonly DAL.PrvFunctList dal = new DAL.PrvFunctList();
        public PrvFunctList()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string FFunctNo, string FPreFunctNo)
        {
            return dal.Exists(FFunctNo, FPreFunctNo);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.PrvFunctList model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.PrvFunctList model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string FFunctNo, string FPreFunctNo)
        {

            dal.Delete(FFunctNo, FPreFunctNo);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.PrvFunctList GetModel(string FFunctNo, string FPreFunctNo)
        {

            return dal.GetModel(FFunctNo, FPreFunctNo);
        }

    
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.PrvFunctList> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.PrvFunctList> DataTableToList(DataTable dt)
        {
            List<Model.PrvFunctList> modelList = new List<Model.PrvFunctList>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PrvFunctList model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PrvFunctList();
                    model.FFunctNo = dt.Rows[n]["FFunctNo"].ToString();
                    model.FPreFunctNo = dt.Rows[n]["FPreFunctNo"].ToString();
                    model.FfunctName = dt.Rows[n]["FfunctName"].ToString();
                    model.FfunctURL = dt.Rows[n]["FfunctURL"].ToString();
                    model.FfunctType = dt.Rows[n]["FfunctType"].ToString();
                    model.Fnote = dt.Rows[n]["Fnote"].ToString();
                    model.FFunctAlias = dt.Rows[n]["FFunctAlias"].ToString();
                    model.FPictName = dt.Rows[n]["FPictName"].ToString();
                    model.FPictSelected = dt.Rows[n]["FPictSelected"].ToString();
                    if (dt.Rows[n]["Fsort"].ToString() != "")
                    {
                        model.Fsort = int.Parse(dt.Rows[n]["Fsort"].ToString());
                    }
                    model.fvisible = dt.Rows[n]["fvisible"].ToString();
                    model.FfunctFullname = dt.Rows[n]["FfunctFullname"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法


        #region 自己增加的方法

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList1(string strWhere)
        {
            return dal.GetList1(strWhere);
        }

        /// <summary>
        /// 得到一个对象实体,根据菜单编号
        /// </summary>
        public Model.PrvFunctList GetModelByFunctNo(string FFunctNo)
        {
            return dal.GetModelByFunctNo(FFunctNo);
        }


        public DataSet getFunctList(string strLogId, string strEntityNo)
        {
            BLL.PrvUserGroup usergroupBll = new PrvUserGroup();
            List<string> str = usergroupBll.getListbyFlogidAndEntityNo(strLogId, strEntityNo);
            DataSet ds = dal.getFunctList(str, strEntityNo);

            List<string> list = new List<string>();
            List<int> listint = new List<int>();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (!list.Contains(ds.Tables[0].Rows[i]["ffunctno"].ToString()))
                {
                    list.Add(ds.Tables[0].Rows[i]["ffunctno"].ToString());
                }
                else
                {
                    listint.Add(i);
                }
            }

            int t = 0;
            foreach (int i1 in listint)
            {
                ds.Tables[0].Rows.RemoveAt(i1 - t);
                t++;
            }

            return ds;
        }


        /// <summary>
        /// 更新一条数据，根据菜单项编号
        /// </summary>
        public void UpdateByFunctNo(Model.PrvFunctList model)
        {
            dal.UpdateByFunctNo(model);
        }

        /// <summary>
        /// 删除一条数据,根据菜单编号
        /// </summary>
        public void DeleteByFunctNo(string FFunctNo)
        {
            dal.DeleteByFunctNo(FFunctNo);
        }

        /// <summary>
        /// 获取菜单编号
        /// </summary>
        /// <param name="str"></param>
        /// <param name="strEntityNo"></param>
        /// <returns></returns>
        public List<string> getFunctNo(string str, string strEntityNo)
        {
            return dal.getFunctNo(str, strEntityNo);
        }

        #endregion

    }
}

